package com.ymatou.iapi.godmch.testcase;

import java.util.List;
import java.util.Map;

import org.apache.commons.collections.map.HashedMap;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.setBizConfigBean;
import com.ymatou.iapi.godmch.service.setBizConfigCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.godmch.biz_config;
import com.ymttest.database.model.godmch.biz_configExample;
import com.ymttest.database.sqlwapper.godmch.biz_configWapper;
import com.ymttest.utils.TestDataManager;
/**
*设置业务配置参数
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_setBizConfig{
	private static setBizConfigBean bean;
	private static setBizConfigCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置业务配置参数");
	}

	@Before
	public void caseUp() {
		bean=new setBizConfigBean();
		call=new setBizConfigCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setBizConfig_001() {
		Logger.start(true,"设置业务配置参数");
		try {
            Integer bizId=Integer.parseInt(TestDataManager.getRandomNum(5));
            String key="key_"+TestDataManager.getRandomNum(5);
            String value="value"+TestDataManager.getRandomNum(5);
			Map<String,String> map=new HashedMap();
			map.put(key, value);
			map.put(key+"_1", value+"_1");
			bean.setBizId(bizId);
			bean.setBizConfigMap(map);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals(200, call.getStatusCode(), "验证status");
			
			biz_configExample example=new biz_configExample();
			example.createCriteria().andBiz_idEqualTo(bizId).andBiz_keyEqualTo(key).andBiz_valueEqualTo(value);
			biz_configWapper bizWapper=new biz_configWapper();
			biz_config biz= bizWapper.selectByExample(example).get(0);
			Logger.verifyEquals(bizId, biz.getBiz_id(), "验证与数据库中的biz_id一致");
			Logger.verifyEquals(key, biz.getBiz_key(), "验证与数据库中的Biz_key一致");
			Logger.verifyEquals(value, biz.getBiz_value(), "验证与数据库中的Biz_value一致");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}